<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="586px" top="0" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="16">
				<el-col :span="18" v-if="formData.id !== '1'">
					<el-form-item label="上级栏目" prop="pid">
						<sw-search-tree-select v-model="formData.pid" v-bind="treeSelectConfig" :tree-data="treeListData" :disabled="isDisabled" />
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="formData.id !== '1'">
					<el-form-item label="是否外链" prop="isOutsite">
						<el-switch v-model="formData.isOutsite" active-value="1" inactive-value="2" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="栏目名称" prop="name">
						<el-input v-model="formData.name" maxlength="6"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="formData.id !== '1'">
					<el-form-item label="栏目链接" prop="value">
						<el-input v-model="formData.value"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="formData.id !== '1'">
					<el-form-item label="是否显示" prop="isShow">
						<el-radio-group v-model="formData.isShow" v-removeAriaHidden:radio>
							<el-radio label="1">显示</el-radio>
							<el-radio label="2">隐藏</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="formData.id !== '1'">
					<el-form-item label="排序" prop="orderBy">
						<el-input-number v-model="formData.orderBy" controls-position="right" :min="1" style="width: 100%" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="栏目描述">
						<el-input type="textarea" v-model="formData.des"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm()">{{ formTypeName }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import lodash from 'lodash';
import formMixins from '@/mixins/formMixins';
import { columnDetail, addedColumn, updateColumn } from '@/api/website/sysWebColumn';
export default {
	mixins: [formMixins],
	props: {
		list: { type: Array, default: () => [] }
	},
	data() {
		return {
			formName: '栏目',
			formRules: {
				pid: [{ required: true, message: '请选择上级栏目', trigger: 'change' }],
				name: [{ required: true, message: '请输入栏目名称', trigger: 'blur' }],
				value: [{ required: true, message: '请输入栏目路径', trigger: 'blur' }],
				isShow: [{ required: true, message: '请选择显示状态', trigger: 'change' }]
			},
			treeSelectConfig: {
				placeholder: '选择顶部导航',
				style: { width: '100%' },
				defaultProps: { label: 'name', children: 'children' }
			}
		};
	},
	computed: {
		detailData() {
			return eval(columnDetail);
		},
		callFunction() {
			return eval(!this.addOrEdit && !this.child ? updateColumn : addedColumn);
		},
		isDisabled() {
			return !!this.child;
		},
		treeListData() {
			let list = this.$treeToFlat(this.list);
			let lists = lodash.reject(list, { isOutsite: '1' });
			let children = this.$flatToTree(lists, 'pid');
			return [{ id: '0', name: '顶部导航', children }];
		},
		submitParams() {
			let datas = { ...this.formData };
			datas['classType'] = '1';
			datas['isOutsite'] = '2';
			return datas;
		}
	},
	methods: {}
};
</script>
